package cn.edu.ujs.coor.repository.relation;

import cn.edu.ujs.coor.model.RoleUserRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RoleUserRelationRepository extends JpaRepository<RoleUserRelation, String>, JpaSpecificationExecutor<RoleUserRelation> {

    /**
     * 根据用户编号查询角色编号
     * @param userId
     * @return
     */
    @Query(value = "select role_id from coor_role_user where user_id = ?1", nativeQuery = true)
    List<String> findByUserId (String userId);

    /**
     * 根据角色编号删除
     * @param roleId
     */
    void deleteByRoleId (String roleId);

    /**
     * 根据用户编号删除
     * @param userId
     */
    void deleteByUserId (String userId);
}
